// pages/index/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    studyDay:"",
    title:"",
    projectId:"",
    projectSelectId:"",
    rate:"今日还未刷题"
  },

  navigator:function(){
    wx.navigateTo({
      url: '/pages/yearSelect/yearSelect',
    })
  },

  navigator1:function(){
    wx.navigateTo({
      url: '/pages/chapterSelect/chapterSelect',
    })
    
  },



  navigatorToLine:function(){
    wx.navigateTo({
      url: '/pages/line/line',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
   
  },

  getWrongRate:function(){
    var _this = this
    wx.request({
      url: 'http://localhost:8081/exam/getWrongRate',
      data:{projectId:_this.data.projectId,projectSelectId:_this.data.projectSelectId},
      success:function(res){
        if(res.data.data==null){
          _this.setData({
            rate:"今日还未刷题"
          })
        }else{
        _this.setData({
          rate:res.data.data
        })
      }
      }
    })
  },

  navigator2:function(){
    var _this = this
    wx.setStorage({
      key:"data",
      data:["3",_this.data.projectId,_this.data.projectSelectId]
    })
    wx.navigateTo({
      url: '/pages/exam/exam',
    })
  },

  getSudyDay:function(){
    var _this = this
    wx.request({
      url: 'http://localhost:8081/exam/getStudyDay',
      data:{projectId:_this.data.projectId,projectSelectId:_this.data.projectSelectId},
      success:function(res){
        console.log(res.data);
        _this.setData({
          studyDay:res.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var _this = this
    wx.getStorage({
      key:"data",
      success:function(res){
        _this.data.projectId = res.data[1]
        _this.data.projectSelectId = res.data[2]
        _this.getWrongRate()
        _this.getSudyDay()
        wx.request({
          url: 'http://localhost:8081/exam/getProjectSelect',
          data:{projectId:res.data[1]},
          method:"get",
          success:function(res1){
            var index = res.data[2]-1
            console.log(res1.data);
            _this.setData({
              title:res1.data.data[index]
            })
          }
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  navigatorToWrong:function(){
    wx.redirectTo({
      url: '/pages/wrongList/wrongList',
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})